$(function(){
	$(".td-item-djs span").each(function(i,n){
		var starttime = parseInt($(this).attr("data-starttime"))*1000;
		var overtime = parseInt($(this).attr("data-overtime"))*1000;
		var timer = overtime - starttime;
		var divname = $(this);
		if (timer >=0){
			window.setInterval(function() {
				ShowCountDown(timer, divname);
				timer = timer - 1000;
			}, 1000);
		}
		
	});


	function ShowCountDown(leftTime, divname) {
		//var now = new Date();
		//var endDate = new Date(year, month - 1, day);
		//var leftTime = timer - now.getTime();
		var leftsecond = parseInt(leftTime / 1000);
		var day1 = Math.floor(leftsecond / (60 * 60 * 24));
		var hour = addZero(Math.floor((leftsecond - day1 * 24 * 60 * 60) / 3600));
		var minute = addZero(Math.floor((leftsecond - day1 * 24 * 60 * 60 - hour * 3600) / 60));
		var second = addZero(Math.floor(leftsecond - day1 * 24 * 60 * 60 - hour * 3600 - minute * 60));
		if( hour > 0 || minute > 0 || second > 0 ){
			divname[0].innerHTML = minute + "分" + second + "秒";
		}else if(hour == 0 || minute == 0 || second == 0){
			var y_price = divname.parents(".J_ItemBody").find(".td-sum-del").text();			
			divname.parent(".td-item-djs").hide();
			divname.parents(".J_ItemBody").find(".td-sum-del").parent(".td-inner").hide();
			divname.parents(".J_ItemBody").find(".J_ItemSum.number,.J_Price.price-now").text(y_price);			
		}
		
		
	}
	function addZero(num){
		var arr=["0","1","2","3","4","5","6","7","8","9"];
		for (var i = 0; i < arr.length; i++) {
			if(num == arr[i]){
				num = "0"+num;
			}
		}
		return num;
	}

});